package com.bionet.ssoservice.controller;


import cn.dev33.satoken.secure.SaSecureUtil;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bionet.service_base.utils.Result;
import com.bionet.ssoservice.entity.AclUser;
import com.bionet.ssoservice.service.AclUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author hzx
 * @since 2021-09-19
 */
@RestController
@RequestMapping("/ssoservice/acl-user")
public class AclUserController {
    @Autowired
    AclUserService aclUserService;

    @PostMapping("/addUser")
    public Result addUser(@RequestBody AclUser aclUser){
        //验证是否可用
        Result register = aclUserService.register(aclUser);
        return register;
    }

    @PostMapping("/checkPassword")
    public Result checkPassword(@RequestBody AclUser aclUser){
        Result login = aclUserService.login(aclUser);
        return login;
    }

    @PostMapping("/checkIsContainUser")
    public Result checkIsContainUser(String username){
        QueryWrapper<AclUser> aclUserQueryWrapper = new QueryWrapper<>();
        aclUserQueryWrapper.eq("username", username);
        int equals = aclUserService.count(aclUserQueryWrapper);
        if (equals>0){
            return Result.error().message("用户名已存在");
        }else {
            return Result.ok();
        }
    }
}

